package com.boss.service.impl;

import com.boss.mappeer.StudentMapper;
import com.boss.mappeer.UserMapper;
import com.boss.pojo.Course;
import com.boss.pojo.Evaluations;
import com.boss.pojo.PageBean;
import com.boss.service.StudentService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentMapper studentMapper;


    //根据用户id查询已选课程
    @Override
    public List<Course> getCourseList(Integer id) {

        return studentMapper.getCourseById(id);
    }

    //根据用户id查询历史评教
    @Override
    public PageBean getEvaluationList(Integer id, Integer pageNum, Integer pageSize) {
        //设置分页参数
        PageHelper.startPage(pageNum, pageSize);
        //执行查询
        List<Evaluations>list=studentMapper.getEvaluationList(id);
        Page<Evaluations> page= (Page<Evaluations>) list;
        //封装pageBean
        PageBean pageBean=new PageBean(page.getTotal(),page.getResult());
        return pageBean;
    }

    //添加评教
    @Override
    public void addEvaluation(Evaluations evaluations) {
        studentMapper.addEvaluation(evaluations);

    }

    //根据评教id查询评教
    @Override
    public Evaluations getEvaluation(Integer studentId, Integer courseId) {
        return studentMapper.getEvaluation(studentId, courseId);
    }

    //根据用户id分页查询课程
    @Override
    public PageBean getPageByUserId(Integer id, Integer pageNum, Integer pageSize) {
        //设置分页参数
        PageHelper.startPage(pageNum, pageSize);
        //执行查询
        List<Course>list=studentMapper.getCourseById(id);
        Page<Course> page= (Page<Course>) list;
        //封装pageBean
        PageBean pageBean=new PageBean(page.getTotal(),page.getResult());
        return pageBean;

    }
}
